package com.treasure.service.common.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import com.treasure.service.BaseService;

import lombok.extern.slf4j.Slf4j;

@Service("imageService")
@Slf4j
public class ImageServiceImpl extends BaseService implements ImageService {
    @Autowired
    private RestTemplate restTemplate;
	@Override
	public String getHaiBao(String type) {
//        String url = restClient.post(this.getGateway()+"/common/v1/getImage",type,String.class);
//		return url;
		MultiValueMap<String, Object> map = new LinkedMultiValueMap();
		map.set("type",type);

		HttpHeaders httpHeaders = new HttpHeaders();
		HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(map, httpHeaders);
		ParameterizedTypeReference<String> pt = new ParameterizedTypeReference<String>() {
		};
		try {
			ResponseEntity<String> resp = restTemplate.exchange(this.getGateway() + "/common/v1/getImage",HttpMethod.POST, formEntity, pt);
			return resp.getBody();
		} catch (HttpClientErrorException e) {
			log.error("请求方法 "+this.getGateway() + "/common/v1/getImage statusCode : {} error:{} ", e.getStatusCode(), e);
		}
		return null;
	}

}
